﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//new
using System.Xml;
using DataRecv.enums;
using System.Collections;
using DataRecv.models;
using System.IO;
using DataRecv.models.device;
using DataRecv.models.road;

namespace DataRecv
{
    public partial class param : Form
    {

        private Pen pen = new Pen(Color.Green, 2f);
        private TreeNode lastnode;

        private Point startpoint = new Point();//矩形起点
        private Point endpoint = new Point();//矩形终点
        private bool blnDraw = false;//是否开始画矩形
        private int m_cd = 0;
        private Graphics g;
        private int kkcount = 0;
        private int djcount = 0;
        private int kkpushcount = 0;
        private int djpushcount = 0;

        bool start = false;
        public param()
        {
            InitializeComponent();
        }

        private void param_Load(object sender, EventArgs e)
        {
            try
            {
                #region 1卡口参数
                checkBox_kkupload.Checked = G.SystemParam.KKUploadEnable;
                textBox_kkuploadip.Text = G.SystemParam.KKUploadIP;
                textBox_kkuploadport.Text = G.SystemParam.KKUploadPort;
                checkBox_KKFailReTry.Checked = G.SystemParam.KKFailReTryEnable;
                comboBox_kknametype.DataSource = Enum.GetNames(typeof(Enum_PicNameMode));
                comboBox_kknametype.SelectedIndex = (int)G.SystemParam.KKPicNameMode;
                comboBox_kksubfolder.DataSource = Enum.GetNames(typeof(Enum_SubFolderMode));
                comboBox_kksubfolder.SelectedIndex = (int)G.SystemParam.KKSubFolderMode;
                textBox_kksavedays.Text = G.SystemParam.KKSaveDays.ToString();
                checkBox_kktailEnable.Checked = G.SystemParam.KKTailEnable;
                label_kkdiy.Text = G.SystemParam.KKDiy;
                checkBox_kkplateenable.Checked = G.SystemParam.KKPlateEnable;
                label_kkname.Text = G.SystemParam.KKNameDiy;
                kkcount = GetKKFailCount();
                this.label_kkcount.Text = kkcount + "条";
                checkBox_kkpushenable.Checked = G.SystemParam.KKPushEnable;
                checkBox_kkrepushenable.Checked = G.SystemParam.KKRePushEnable;
                kkpushcount = GetKKPushCount();
                this.label_kkpushcount.Text = kkpushcount + "条";
                #endregion

                #region 2电警参数
                checkBox_djupload.Checked = G.SystemParam.DJUploadEnable;
                textBox_djuploadip.Text = G.SystemParam.DJUploadIP;
                textBox_djuploadport.Text = G.SystemParam.DJUploadPort;
                checkBox_DJFailReTry.Checked = G.SystemParam.DJFailReTryEnable;
                cboPicCheck.Checked = G.SystemParam.DJPicCheck;
                comboBox_djnametype.DataSource = Enum.GetNames(typeof(Enum_PicNameMode));
                comboBox_djnametype.SelectedIndex = (int)G.SystemParam.DJPicNameMode;
                comboBox_djsubfolder.DataSource = Enum.GetNames(typeof(Enum_SubFolderMode));
                comboBox_djsubfolder.SelectedIndex = (int)G.SystemParam.DJSubFolderMode;
                checkBox_djcompress.Checked = G.SystemParam.DJCompressEnable;
                textBox_compress.Text = G.SystemParam.DJCompressValue;
                checkBox_DJPlateFilterEnable.Checked = G.SystemParam.DJPlateFilterEnable;
                if (G.SystemParam.DJPlateFilterType.Equals(G.SystemParam.DJPlateFilterType | Enum_PlateFilterType.无牌过滤)) checkBox_FiltNoPlate.Checked = true;
                if (G.SystemParam.DJPlateFilterType.Equals(G.SystemParam.DJPlateFilterType | Enum_PlateFilterType.黄牌过滤)) checkBox_FiltYellowPlate.Checked = true;
                if (G.SystemParam.DJPlateFilterType.Equals(G.SystemParam.DJPlateFilterType | Enum_PlateFilterType.蓝牌过滤)) checkBox_FiltBluePlate.Checked = true;
                textBox_djsavedays.Text = G.SystemParam.DJSaveDays.ToString();
                checkBox_djtailEnable.Checked = G.SystemParam.DJTailEnable;
                label_djdiy.Text = G.SystemParam.DJDiy;
                checkBox_djplateenable.Checked = G.SystemParam.DJPlateEnable;
                label_djname.Text = G.SystemParam.DJNameDiy;
                djcount = GetDJFailCount();
                this.label_djcount.Text = djcount + "条";
                checkBox_djpushenable.Checked = G.SystemParam.DJPushEnable;
                checkBox_djrepushenable.Checked = G.SystemParam.DJRePushEnable;
                djpushcount = GetDJPushCount();
                this.label_djpushcount.Text = djpushcount + "条";
                #endregion

                #region 3抓拍参数
                this.dataGridView1.Rows.Clear();
                if (G.SystemParam.SnapParams != null)
                {
                    IDictionaryEnumerator ide = G.SystemParam.SnapParams.GetEnumerator();
                    ide.Reset();
                    while (ide.MoveNext())
                    {
                        SnapParam sp = (SnapParam)ide.Value;
                        this.dataGridView1.Rows.Add(new string[] { sp.snaptype.ToString(), sp.snapcount.ToString(), sp.platefrom.ToString(), sp.speedfrom.ToString(), sp.timefrom.ToString(), sp.otherfrom.ToString() });
                    }
                }
                #endregion

                #region 4违法代码
                this.dataGridView2.Rows.Clear();
                if (G.SystemParam.Wfxwdms != null)
                {
                    IDictionaryEnumerator ide = G.SystemParam.Wfxwdms.GetEnumerator();
                    ide.Reset();
                    while (ide.MoveNext())
                    {
                        VioParam w = (VioParam)ide.Value;
                        this.dataGridView2.Rows.Add(new string[] { w.viotype.ToString(), w.viocode, w.viodescribe, w.bz });
                    }
                }
                #endregion

                #region 5图片合成
                switch (G.SystemParam.TwoPicsJoinMode)
                { 
                    case Enum_PicJoinMode.No:
                        radioButton_No2.Checked = true;
                        radioButton_A2.Checked = false;
                        radioButton_B2.Checked = false;
                        break;
                    case Enum_PicJoinMode.A2:
                        radioButton_No2.Checked = false;
                        radioButton_A2.Checked = true;
                        radioButton_B2.Checked = false;
                        break;
                    case Enum_PicJoinMode.B2:
                        radioButton_No2.Checked = false;
                        radioButton_A2.Checked = false;
                        radioButton_B2.Checked = true;
                        break;
                    default:
                        radioButton_No2.Checked = true;
                        radioButton_A2.Checked = false;
                        radioButton_B2.Checked = false;
                        break;
                }
                switch (G.SystemParam.ThreePicsJoinMode)
                {
                    case Enum_PicJoinMode.No:
                        radioButton_No3.Checked = true;
                        radioButton_A3.Checked = false;
                        radioButton_B3.Checked = false;
                        break;
                    case Enum_PicJoinMode.A3:
                        radioButton_No3.Checked = false;
                        radioButton_A3.Checked = true;
                        radioButton_B3.Checked = false;
                        break;
                    case Enum_PicJoinMode.B3:
                        radioButton_No3.Checked = false;
                        radioButton_A3.Checked = false;
                        radioButton_B3.Checked = true;
                        break;
                    default:
                        radioButton_No3.Checked = true;
                        radioButton_A3.Checked = false;
                        radioButton_B3.Checked = false;
                        break;
                }
                switch (G.SystemParam.FourPicsJoinMode)
                {
                    case Enum_PicJoinMode.No:
                        radioButton_No4.Checked = true;
                        radioButton_A4.Checked = false;
                        radioButton_B4.Checked = false;
                        break;
                    case Enum_PicJoinMode.A4:
                        radioButton_No4.Checked = false;
                        radioButton_A4.Checked = true;
                        radioButton_B4.Checked = false;
                        break;
                    case Enum_PicJoinMode.B4:
                        radioButton_No4.Checked = false;
                        radioButton_A4.Checked = false;
                        radioButton_B4.Checked = true;
                        break;
                    default:
                        radioButton_No4.Checked = true;
                        radioButton_A4.Checked = false;
                        radioButton_B4.Checked = false;
                        break;
                }
                #endregion

                #region 6特写区域
                g = this.pictureBox1.CreateGraphics();

                treeView1.Nodes.Clear();
                if (G.Roads != null)
                {
                    IDictionaryEnumerator ide = G.Roads.GetEnumerator();
                    ide.Reset();
                    while (ide.MoveNext())
                    {
                        Road road = (Road)ide.Value;
                        TreeNode roadnode = new TreeNode();
                        roadnode.Text = road.param.roadname;
                        roadnode.Tag = road.param.roadid;
                        roadnode.Name = "road_" + road.param.roadid;
                        treeView1.Nodes.Add(roadnode);
                    }
                }

                if (G.Views != null)
                {
                    IDictionaryEnumerator idd = G.Views.GetEnumerator();
                    idd.Reset();
                    while (idd.MoveNext())
                    {
                        DeviceView view = (DeviceView)idd.Value;
                        TreeNode[] roadnode = this.treeView1.Nodes.Find("road_" + view.roadparam.roadid, true);
                        if ((roadnode != null) && (roadnode.Length == 1))
                        {
                            TreeNode camnode = new TreeNode();
                            camnode.Text = view.deviceparam.ip + "---" + view.deviceparam.direction.ToString();
                            camnode.Tag = view.deviceparam.ip;
                            camnode.Name = "device_" + view.deviceparam.ip;
                            roadnode[0].Nodes.Add(camnode);
                        }
                    }
                }
                treeView1.ExpandAll();
                #endregion

                #region 7字符叠加
                checkBox_printEnable.Checked = G.SystemParam.PrintEnable;
                checkBox_printtime.Checked = G.SystemParam.PrintTime;
                checkBox_printroad.Checked = G.SystemParam.PrintRoad;
                checkBox_printdirection.Checked = G.SystemParam.PrintDirection;
                checkBox_printcd.Checked = G.SystemParam.PrintCD;
                checkBox_printcapturesystem.Checked = G.SystemParam.PrintCaptureSystem;
                checkBox_printplatecolor.Checked = G.SystemParam.PrintPlateColor;
                checkBox_printhphm.Checked = G.SystemParam.PrintHPHM;
                checkBox_printsbbh.Checked = G.SystemParam.PrintSBBH;
                checkBox_printfwm.Checked = G.SystemParam.PrintFWM;
                switch (G.SystemParam.PrintPosition)
                { 
                    case Enum_PrintPosition.Down:
                        radioButton_printdown.Checked = true;
                        radioButton_printtop.Checked = false;
                        break;
                    case Enum_PrintPosition.Top:
                        radioButton_printdown.Checked = false;
                        radioButton_printtop.Checked = true;
                        break;
                    default:
                        break;
                }
                #endregion

                #region 8其他参数
                textBox_localIP.Text = G.SystemParam.LocalIP;
                checkBox_useHardWatch.Checked = G.SystemParam.DogEnable;
                checkBox_useAutoShutDown.Checked = G.SystemParam.DogEnableShutDown;
                checkBox_usesoftRestart.Checked = G.SystemParam.DailyCloseEnable;
                numericUpDown_ShutDownHour.Value = decimal.Parse(G.SystemParam.DogShutDownHour);
                numericUpDown_ShutDownMinute.Value = decimal.Parse(G.SystemParam.DogShutDownMin);
                numericUpDown_ShutDownTimeSpan.Value = decimal.Parse(G.SystemParam.DogShutDownSpan);
                comboBox_SerialPort.Text = G.SystemParam.DogPort;
                numericUpDown_RestartHour.Value = decimal.Parse(G.SystemParam.DailyCloseHour);
                numericUpDown_RestartMinute.Value = decimal.Parse(G.SystemParam.DailyCloseMin);
                textBox_SynServerIP.Text = G.SystemParam.SynServerIP;
                textBox_SynServerPort.Text = G.SystemParam.SynServerPort;
                checkBox_useHardWatch_CheckedChanged(sender, e);
                checkBox_usesoftRestart_CheckedChanged(sender, e);
                checkBox_djcompress_CheckedChanged(sender, e);
                checkBox_kkupload_CheckedChanged(sender, e);
                checkBox_djupload_CheckedChanged(sender, e);
                switch (G.SystemParam.WebPathType)
                {
                    case Enum_WebPathType.HTTP:
                        radioButton_http.Checked = true;
                        radioButton_ftp.Checked = false;
                        break;
                    case Enum_WebPathType.FTP:
                        radioButton_http.Checked = false;
                        radioButton_ftp.Checked = true;
                        break;
                    default:
                        radioButton_http.Checked = true;
                        radioButton_ftp.Checked = false;
                        break;
                }
                textBox_mquri.Text = G.SystemParam.MqUri;
                textBox_mqtopic.Text = G.SystemParam.MqTopic;
                textBox_pushport.Text = G.SystemParam.PushPort;
                switch (G.SystemParam.PushWorkMode)
                {
                    case JRCore.enums.Enum_TcpWorkMode.Send:
                        radioButton_Send.Checked = true;
                        radioButton_SendRead.Checked = false;
                        break;
                    case JRCore.enums.Enum_TcpWorkMode.SendRead:
                        radioButton_Send.Checked = false;
                        radioButton_SendRead.Checked = true;
                        break;
                    default:
                        radioButton_Send.Checked = true;
                        radioButton_SendRead.Checked = false;
                        break;
                }
                textBox_pushtimeout.Text = G.SystemParam.PushTimeOut;
                #endregion
            }
            catch { }
        }

        private void button_addcamtype_Click(object sender, EventArgs e)
        {
            MessageBox.Show("输入管理员密码:");
        }

        
        private void checkBox_useHardWatch_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_useHardWatch.Tag = true;
            }
            if (this.checkBox_useHardWatch.Checked)
            {
                this.checkBox_useAutoShutDown.Visible = true;
                this.label_serianport.Visible = true;
                this.comboBox_SerialPort.Visible = true;
                checkBox_useAutoShutDown_CheckedChanged(sender, e);
            }
            else
            {
                this.label_serianport.Visible = false;
                this.label_shutdowntime.Visible = false;
                this.label_shutdowntimespan.Visible = false;
                this.numericUpDown_ShutDownHour.Visible = false;
                this.numericUpDown_ShutDownMinute.Visible = false;
                this.numericUpDown_ShutDownTimeSpan.Visible = false;
                this.comboBox_SerialPort.Visible = false;
                this.checkBox_useAutoShutDown.Visible = false;
                this.label_h.Visible = false;
                this.label_hh.Visible = false;
                this.label_hhh.Visible = false;
            }

        }

        private void checkBox_usesoftRestart_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_usesoftRestart.Tag = true;
            }
            this.label_restarttime.Visible = checkBox_usesoftRestart.Checked;
            this.label_hhhh.Visible = checkBox_usesoftRestart.Checked;
            this.label_hhhhh.Visible = checkBox_usesoftRestart.Checked;
            this.numericUpDown_RestartHour.Visible = checkBox_usesoftRestart.Checked;
            this.numericUpDown_RestartMinute.Visible = checkBox_usesoftRestart.Checked;

        }

        private void checkBox_useAutoShutDown_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_useAutoShutDown.Tag = true;
            }
            this.label_h.Visible = checkBox_useAutoShutDown.Checked;
            this.label_hh.Visible = checkBox_useAutoShutDown.Checked;
            this.label_hhh.Visible = checkBox_useAutoShutDown.Checked;
            this.label_shutdowntime.Visible = checkBox_useAutoShutDown.Checked;
            this.label_shutdowntimespan.Visible = checkBox_useAutoShutDown.Checked;
            this.numericUpDown_ShutDownHour.Visible = checkBox_useAutoShutDown.Checked;
            this.numericUpDown_ShutDownMinute.Visible = checkBox_useAutoShutDown.Checked;
            this.numericUpDown_ShutDownTimeSpan.Visible = checkBox_useAutoShutDown.Checked;

        }

        private void checkBox_djcompress_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_djcompress.Tag = true;
            }
        }

        private void checkBox_kkupload_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_kkupload.Tag = true;
            }
        }

        private void checkBox_djupload_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_djupload.Tag = true;
            }
        }

        private void button_cancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button_ok_Click(object sender, EventArgs e)
        {
            int total = 0;
            int count = 0;
            bool flag = false;
            try
            {
                #region 卡口参数
                
                if (checkBox_kkupload.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.KKUploadEnable, checkBox_kkupload.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_kkupload.Tag = null;
                        G.SystemParam.KKUploadEnable = checkBox_kkupload.Checked;
                    }
                }

                if (textBox_kkuploadip.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.KKUploadIP, textBox_kkuploadip.Text);
                    if (flag == true)
                    {
                        count++;
                        textBox_kkuploadip.Tag = null;
                        G.SystemParam.KKUploadIP = textBox_kkuploadip.Text;
                    }
                }

                if (textBox_kkuploadport.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.KKUploadPort, textBox_kkuploadport.Text);
                    if (flag == true)
                    {
                        count++;
                        textBox_kkuploadport.Tag = null;
                        G.SystemParam.KKUploadPort = textBox_kkuploadport.Text;
                    }
                }

                if (checkBox_KKFailReTry.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.KKFailReTryEnable, checkBox_KKFailReTry.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_KKFailReTry.Tag = null;
                        G.SystemParam.KKFailReTryEnable = checkBox_KKFailReTry.Checked;
                    }
                }

                if (comboBox_kknametype.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.KKPicNameMode, comboBox_kknametype.Text)&&
                        G.SystemParam.Save(Enum_SystemParamName.KKNameDiy,label_kkname.Text);
                    if (flag == true)
                    {
                        count++;
                        comboBox_kknametype.Tag = null;
                        G.SystemParam.KKPicNameMode = (Enum_PicNameMode)Enum.Parse(typeof(Enum_PicNameMode), comboBox_kknametype.Text);
                        G.SystemParam.KKNameDiy = label_kkname.Text;
                    }
                }

                if (comboBox_kksubfolder.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.KKSubFolderMode, comboBox_kksubfolder.Text)&&
                        G.SystemParam.Save(Enum_SystemParamName.KKDiy, label_kkdiy.Text);
                    if (flag == true)
                    {
                        count++;
                        comboBox_kksubfolder.Tag = null;
                        G.SystemParam.KKSubFolderMode = (Enum_SubFolderMode)Enum.Parse(typeof(Enum_SubFolderMode), comboBox_kksubfolder.Text);
                        G.SystemParam.KKDiy = label_kkdiy.Text;
                    }
                }

                if (textBox_kksavedays.Tag!=null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.KKSaveDays, int.Parse(textBox_kksavedays.Text));
                    if (flag == true)
                    {
                        count++;
                        textBox_kksavedays.Tag = null;
                        G.SystemParam.KKSaveDays = int.Parse(textBox_kksavedays.Text);
                    }
                }

                if (checkBox_kktailEnable.Tag != null)
                { 
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.KKTailEnable, checkBox_kktailEnable.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_kktailEnable.Tag = null;
                        G.SystemParam.KKTailEnable = checkBox_kktailEnable.Checked;
                    }
                }

                if (checkBox_kkplateenable.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.KKPlateEnable, checkBox_kkplateenable.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_kkplateenable.Tag = null;
                        G.SystemParam.KKPlateEnable = checkBox_kkplateenable.Checked;
                    }
                }

                if (checkBox_kkpushenable.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.KKPushEnable, checkBox_kkpushenable.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_kkpushenable.Tag = null;
                        G.SystemParam.KKPushEnable = checkBox_kkpushenable.Checked;
                    }
                }

                if (checkBox_kkrepushenable.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.KKRePushEnable, checkBox_kkrepushenable.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_kkrepushenable.Tag = null;
                        G.SystemParam.KKRePushEnable = checkBox_kkrepushenable.Checked;
                    }
                }
                #endregion

                #region 电警参数
                if (checkBox_djupload.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJUploadEnable, checkBox_djupload.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_djupload.Tag = null;
                        G.SystemParam.DJUploadEnable = checkBox_djupload.Checked;
                    }
                }

                if (textBox_djuploadip.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJUploadIP, textBox_djuploadip.Text);
                    if (flag == true)
                    {
                        count++;
                        textBox_djuploadip.Tag = null;
                        G.SystemParam.DJUploadIP = textBox_djuploadip.Text;
                    }
                }

                if (textBox_djuploadport.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJUploadPort, textBox_djuploadport.Text);
                    if (flag == true)
                    {
                        count++;
                        textBox_djuploadport.Tag = null;
                        G.SystemParam.DJUploadPort = textBox_djuploadport.Text;
                    }
                }

                if (checkBox_DJFailReTry.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJFailReTryEnable, checkBox_DJFailReTry.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_DJFailReTry.Tag = null;
                        G.SystemParam.DJFailReTryEnable = checkBox_DJFailReTry.Checked;
                    }
                }

                if (cboPicCheck.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJPicCheck,cboPicCheck.Checked);
                    if (flag == true)
                    {
                        count++;
                        cboPicCheck.Tag = null;
                        G.SystemParam.DJPicCheck = cboPicCheck.Checked;
                    }
                }

                if (comboBox_djnametype.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJPicNameMode, comboBox_djnametype.Text) && G.SystemParam.Save(Enum_SystemParamName.DJNameDiy, label_djname.Text);
                    if (flag == true)
                    {
                        count++;
                        comboBox_djnametype.Tag = null;
                        G.SystemParam.DJPicNameMode = (Enum_PicNameMode)Enum.Parse(typeof(Enum_PicNameMode), comboBox_djnametype.Text);
                        G.SystemParam.DJNameDiy = label_djname.Text;
                    }
                }

                if (comboBox_djsubfolder.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJSubFolderMode, comboBox_djsubfolder.Text)&&
                        G.SystemParam.Save(Enum_SystemParamName.DJDiy, label_djdiy.Text);
                    if (flag == true)
                    {
                        count++;
                        comboBox_djsubfolder.Tag = null;
                        G.SystemParam.DJSubFolderMode = (Enum_SubFolderMode)Enum.Parse(typeof(Enum_SubFolderMode), comboBox_djsubfolder.Text);
                        G.SystemParam.DJDiy = label_djdiy.Text;
                    }
                }

                if (checkBox_djcompress.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJCompressEnable, checkBox_djcompress.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_djcompress.Tag = null;
                        G.SystemParam.DJCompressEnable = checkBox_djcompress.Checked;
                    }
                }

                if(textBox_compress.Tag!=null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJCompressValue, textBox_compress.Text);
                    if (flag == true)
                    {
                        count++;
                        textBox_compress.Tag = null;
                        G.SystemParam.DJCompressValue = textBox_compress.Text;
                    }
                }

                if (checkBox_DJPlateFilterEnable.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJPlateFilterEnable, checkBox_DJPlateFilterEnable.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_DJPlateFilterEnable.Tag = null;
                        G.SystemParam.DJPlateFilterEnable = checkBox_DJPlateFilterEnable.Checked;
                    }
                }

                if (checkBox_FiltNoPlate.Tag != null)
                {
                    total++;
                    Enum_PlateFilterType type = Enum_PlateFilterType.不过滤;
                    if (checkBox_FiltNoPlate.Checked) type |= Enum_PlateFilterType.无牌过滤;
                    if (checkBox_FiltYellowPlate.Checked) type |= Enum_PlateFilterType.黄牌过滤;
                    if (checkBox_FiltBluePlate.Checked) type |= Enum_PlateFilterType.蓝牌过滤;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJPlateFilterType, type);
                    if (flag == true)
                    {
                        count++;
                        checkBox_FiltNoPlate.Tag = null;
                        G.SystemParam.DJPlateFilterType = type;
                    }
                }

                if (textBox_djsavedays.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJSaveDays, int.Parse(textBox_djsavedays.Text));
                    if (flag == true)
                    {
                        count++;
                        textBox_djsavedays.Tag = null;
                        G.SystemParam.DJSaveDays = int.Parse(textBox_djsavedays.Text);
                    }
                }

                if (checkBox_djtailEnable.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJTailEnable, checkBox_djtailEnable.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_djtailEnable.Tag = null;
                        G.SystemParam.DJTailEnable = checkBox_djtailEnable.Checked;
                    }
                }

                if (checkBox_djplateenable.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJPlateEnable, checkBox_djplateenable.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_djplateenable.Tag = null;
                        G.SystemParam.DJPlateEnable = checkBox_djplateenable.Checked;
                    }
                }

                if (checkBox_djpushenable.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJPushEnable, checkBox_djpushenable.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_djpushenable.Tag = null;
                        G.SystemParam.DJPushEnable = checkBox_djpushenable.Checked;
                    }
                }

                if (checkBox_djrepushenable.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DJRePushEnable, checkBox_djrepushenable.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_djrepushenable.Tag = null;
                        G.SystemParam.DJRePushEnable = checkBox_djrepushenable.Checked;
                    }
                }
                #endregion

                #region 其他参数

                if (textBox_localIP.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.LocalIP, textBox_localIP.Text);
                    if (flag == true)
                    {
                        count++;
                        textBox_localIP.Tag = null;
                        G.SystemParam.LocalIP = textBox_localIP.Text;
                    }
                }

                if (checkBox_useHardWatch.Tag!=null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DogEnable, checkBox_useHardWatch.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_useHardWatch.Tag = null;
                        G.SystemParam.DogEnable = checkBox_useHardWatch.Checked;
                    }
                }

                if (checkBox_useAutoShutDown.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DogEnableShutDown, checkBox_useAutoShutDown.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_useAutoShutDown.Tag = null;
                        G.SystemParam.DogEnableShutDown = checkBox_useAutoShutDown.Checked;
                    }
                }

                if (comboBox_SerialPort.Tag!=null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DogPort, comboBox_SerialPort.Text);
                    if (flag == true)
                    {
                        count++;
                        comboBox_SerialPort.Tag = null;
                        G.SystemParam.DogPort = comboBox_SerialPort.Text;
                    }
                }

                if (comboBox_SerialPort.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DogPort, comboBox_SerialPort.Text);
                    if (flag == true)
                    {
                        count++;
                        comboBox_SerialPort.Tag = null;
                        G.SystemParam.DogPort = comboBox_SerialPort.Text;
                    }
                }

                if (numericUpDown_ShutDownHour.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DogShutDownHour, numericUpDown_ShutDownHour.Value);
                    if (flag == true)
                    {
                        count++;
                        numericUpDown_ShutDownHour.Tag = null;
                        G.SystemParam.DogShutDownHour = numericUpDown_ShutDownHour.Value.ToString();
                    }
                }

                if (numericUpDown_ShutDownMinute.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DogShutDownMin, numericUpDown_ShutDownMinute.Value);
                    if (flag == true)
                    {
                        count++;
                        numericUpDown_ShutDownMinute.Tag = null;
                        G.SystemParam.DogShutDownMin = numericUpDown_ShutDownMinute.Value.ToString();
                    }
                }

                if (numericUpDown_ShutDownTimeSpan.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DogShutDownSpan, numericUpDown_ShutDownTimeSpan.Value);
                    if (flag == true)
                    {
                        count++;
                        numericUpDown_ShutDownTimeSpan.Tag = null;
                        G.SystemParam.DogShutDownSpan = numericUpDown_ShutDownTimeSpan.Value.ToString();
                    }
                }

                if (checkBox_usesoftRestart.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DailyCloseEnable, checkBox_usesoftRestart.Checked);
                    if (flag == true)
                    {
                        count++;
                        checkBox_usesoftRestart.Tag = null;
                        G.SystemParam.DailyCloseEnable = checkBox_usesoftRestart.Checked;
                    }
                }

                if (numericUpDown_RestartHour.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DailyCloseHour, numericUpDown_RestartHour.Value);
                    if (flag == true)
                    {
                        count++;
                        numericUpDown_RestartHour.Tag = null;
                        G.SystemParam.DailyCloseHour = numericUpDown_RestartHour.Value.ToString();
                    }
                }

                if (numericUpDown_RestartMinute.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.DailyCloseMin, numericUpDown_RestartMinute.Value);
                    if (flag == true)
                    {
                        count++;
                        numericUpDown_RestartMinute.Tag = null;
                        G.SystemParam.DailyCloseMin = numericUpDown_RestartMinute.Value.ToString();
                    }
                }

                if (textBox_SynServerIP.Tag!=null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.SynServerIP, textBox_SynServerIP.Text);
                    if (flag == true)
                    {
                        count++;
                        textBox_SynServerIP.Tag = null;
                        G.SystemParam.SynServerIP = textBox_SynServerIP.Text;
                    }
                }

                if (textBox_SynServerPort.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.SynServerPort, textBox_SynServerPort.Text);
                    if (flag == true)
                    {
                        count++;
                        textBox_SynServerPort.Tag = null;
                        G.SystemParam.SynServerPort = textBox_SynServerPort.Text;
                    }
                }

                if (radioButton_http.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.WebPathType, radioButton_http.Tag);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.WebPathType = (Enum_WebPathType)radioButton_http.Tag;
                        radioButton_http.Tag = null;
                    }
                }

                if (textBox_mquri.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.MqUri, textBox_mquri.Text);
                    if (flag == true)
                    {
                        count++;
                        textBox_mquri.Tag = null;
                        G.SystemParam.MqUri = textBox_mquri.Text;
                    }
                }

                if (textBox_mqtopic.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.MqTopic, textBox_mqtopic.Text);
                    if (flag == true)
                    {
                        count++;
                        textBox_mqtopic.Tag = null;
                        G.SystemParam.MqTopic = textBox_mqtopic.Text;
                    }
                }

                if (textBox_pushport.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PushPort, textBox_pushport.Text);
                    if (flag == true)
                    {
                        count++;
                        textBox_pushport.Tag = null;
                        G.SystemParam.PushPort = textBox_pushport.Text;
                    }
                }

                if (radioButton_Send.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PushWorkMode, radioButton_Send.Tag);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.PushWorkMode = (JRCore.enums.Enum_TcpWorkMode)radioButton_Send.Tag;
                        radioButton_Send.Tag = null;
                    }
                }

                if (textBox_pushtimeout.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PushTimeOut, textBox_pushtimeout.Text);
                    if (flag == true)
                    {
                        count++;
                        textBox_pushtimeout.Tag = null;
                        G.SystemParam.PushTimeOut = textBox_pushtimeout.Text;
                    }
                }
                #endregion

                #region 抓拍参数
                if (dataGridView1.Tag != null)
                {
                    bool fflag = true;
                    total++;
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        Enum_CaptureSystem ab = (Enum_CaptureSystem)Enum.Parse(typeof(Enum_CaptureSystem), row.Cells["snaptype"].Value.ToString());
                        SnapParam newsp = new SnapParam();
                        newsp.snaptype = ab;
                        newsp.snapcount = int.Parse(row.Cells["snapcount"].Value.ToString());
                        newsp.platefrom = int.Parse(row.Cells["platefrom"].Value.ToString());
                        newsp.speedfrom = int.Parse(row.Cells["speedfrom"].Value.ToString());
                        newsp.timefrom = int.Parse(row.Cells["timefrom"].Value.ToString());
                        newsp.otherfrom = int.Parse(row.Cells["otherfrom"].Value.ToString());
                        if ((newsp.snapcount < 1) || (newsp.platefrom < 1) || (newsp.speedfrom < 1) || (newsp.timefrom < 1) || (newsp.otherfrom < 1))
                        {
                            this.toolStripStatusLabel1.Text = "保存失败，" + ab.ToString() + "张数必须>0";
                            return;
                        }
                        if (newsp.platefrom > newsp.snapcount)
                        {
                            this.toolStripStatusLabel1.Text = "保存失败，" + ab.ToString() + "车牌信息来自第" + newsp.platefrom + "张,超过了抓拍张数";
                            return;
                        }
                        if (newsp.speedfrom > newsp.snapcount)
                        {
                            this.toolStripStatusLabel1.Text = "保存失败，" + ab.ToString() + "车速信息来自第" + newsp.speedfrom + "张,超过了抓拍张数";
                            return;
                        }
                        if (newsp.timefrom > newsp.snapcount)
                        {
                            this.toolStripStatusLabel1.Text = "保存失败，" + ab.ToString() + "时间信息来自第" + newsp.timefrom + "张,超过了抓拍张数";
                            return;
                        }
                        if (newsp.otherfrom > newsp.snapcount)
                        {
                            this.toolStripStatusLabel1.Text = "保存失败，" + ab.ToString() + "其他参数来自第" + newsp.otherfrom + "张,超过了抓拍张数";
                            return;
                        }
                        if (G.SystemParam.SnapParams.Contains(ab))
                        {
                            SnapParam sp = (SnapParam)G.SystemParam.SnapParams[ab];
                            if (sp.snapcount != newsp.snapcount || sp.platefrom != newsp.platefrom || sp.speedfrom != newsp.speedfrom || sp.timefrom != newsp.timefrom || sp.otherfrom != newsp.otherfrom)
                            {
                                flag = newsp.Save();
                                if (flag == false)
                                {
                                    fflag = flag;
                                }
                                else
                                {
                                    G.SystemParam.SnapParams[ab] = newsp;
                                }
                            }
                        }
                    }
                    if (fflag == true)
                    {
                        count++;
                        dataGridView1.Tag = null;
                    }
                }
                #endregion

                #region 违法代码
                if (dataGridView2.Tag != null)
                {
                    bool fflag = true;
                    total++;
                    foreach (DataGridViewRow row in dataGridView2.Rows)
                    {
                        Enum_VioType vt = (Enum_VioType)Enum.Parse(typeof(Enum_VioType), row.Cells["viotype"].Value.ToString());
                        VioParam newwfdm = new VioParam();
                        newwfdm.viotype = vt;
                        object obj = row.Cells["viocode"].Value;
                        newwfdm.viocode = (obj == null) ? "" : obj.ToString();
                        obj = row.Cells["viodescribe"].Value;
                        newwfdm.viodescribe = (obj == null) ? "" : obj.ToString();
                        obj = row.Cells["bz"].Value;
                        newwfdm.bz = (obj == null) ? "" : obj.ToString();
                        
                        if (G.SystemParam.Wfxwdms.Contains(vt))
                        {
                            VioParam w = (VioParam)G.SystemParam.Wfxwdms[vt];
                            if (w.viocode != newwfdm.viocode || w.viodescribe != newwfdm.viodescribe || w.bz != newwfdm.bz)
                            {
                                flag = newwfdm.Save();
                                if (flag == false)
                                {
                                    fflag = flag;
                                }
                                else
                                {
                                    G.SystemParam.Wfxwdms[vt] = newwfdm;
                                }
                            }
                        }
                    }
                    if (fflag == true)
                    {
                        count++;
                        dataGridView2.Tag = null;
                    }
                }
                #endregion

                #region 合成参数
                if (radioButton_No2.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.TwoPicsJoinMode, radioButton_No2.Tag);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.TwoPicsJoinMode = (Enum_PicJoinMode)radioButton_No2.Tag;
                        radioButton_No2.Tag = null;
                    }
                }
                if (radioButton_No3.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.ThreePicsJoinMode, radioButton_No3.Tag);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.ThreePicsJoinMode = (Enum_PicJoinMode)radioButton_No3.Tag;
                        radioButton_No3.Tag = null;
                    }
                }
                if (radioButton_No4.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.FourPicsJoinMode, radioButton_No4.Tag);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.FourPicsJoinMode = (Enum_PicJoinMode)radioButton_No4.Tag;
                        radioButton_No4.Tag = null;
                    }
                }
                #endregion

                #region 字符叠加
                if (checkBox_printEnable.Tag!=null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PrintEnable, checkBox_printEnable.Checked);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.PrintEnable = checkBox_printEnable.Checked;
                        checkBox_printEnable.Tag = null;
                    }
                }
                if (checkBox_printtime.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PrintTime, checkBox_printtime.Checked);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.PrintTime = checkBox_printtime.Checked;
                        checkBox_printtime.Tag = null;
                    }
                }
                if (checkBox_printroad.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PrintRoad, checkBox_printroad.Checked);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.PrintRoad = checkBox_printroad.Checked;
                        checkBox_printroad.Tag = null;
                    }
                }
                if (checkBox_printdirection.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PrintDirection, checkBox_printdirection.Checked);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.PrintDirection = checkBox_printdirection.Checked;
                        checkBox_printdirection.Tag = null;
                    }
                }
                if (checkBox_printcd.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PrintCD, checkBox_printcd.Checked);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.PrintCD = checkBox_printcd.Checked;
                        checkBox_printcd.Tag = null;
                    }
                }
                if (checkBox_printcapturesystem.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PrintCaptureSystem, checkBox_printcapturesystem.Checked);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.PrintCaptureSystem = checkBox_printcapturesystem.Checked;
                        checkBox_printcapturesystem.Tag = null;
                    }
                }
                if (checkBox_printplatecolor.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PrintPlateColor, checkBox_printplatecolor.Checked);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.PrintPlateColor = checkBox_printplatecolor.Checked;
                        checkBox_printplatecolor.Tag = null;
                    }
                }
                if (checkBox_printhphm.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PrintHPHM, checkBox_printhphm.Checked);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.PrintHPHM = checkBox_printhphm.Checked;
                        checkBox_printhphm.Tag = null;
                    }
                }
                if (checkBox_printsbbh.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PrintSBBH, checkBox_printsbbh.Checked);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.PrintSBBH = checkBox_printsbbh.Checked;
                        checkBox_printsbbh.Tag = null;
                    }
                }
                if (checkBox_printfwm.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PrintFWM, checkBox_printfwm.Checked);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.PrintFWM = checkBox_printfwm.Checked;
                        checkBox_printfwm.Tag = null;
                    }
                }
                if (radioButton_printtop.Tag != null)
                {
                    total++;
                    flag = G.SystemParam.Save(Enum_SystemParamName.PrintPosition, radioButton_printtop.Tag);
                    if (flag == true)
                    {
                        count++;
                        G.SystemParam.PrintPosition = (Enum_PrintPosition)radioButton_printtop.Tag;
                        radioButton_printtop.Tag = null;
                    }
                }
                #endregion

                if ((count == total) && (total != 0))
                {
                    this.toolStripStatusLabel1.Text = "保存成功";
                    button_ok.Enabled = false;
                }
                else
                {
                    this.toolStripStatusLabel1.Text = "保存失败";
                }
            }
            catch { }
        }

        private void textBox_kkuploadip_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_kkuploadip.Tag = true;
            }
        }

        private void textBox_kkuploadport_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_kkuploadport.Tag = true;
            }
        }

        private void checkBox_KKFailReTry_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_KKFailReTry.Tag = true;
            }
        }

        private void comboBox_kknametype_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                comboBox_kknametype.Tag = true;

                if (comboBox_kknametype.Text == Enum_PicNameMode.自定义.ToString())
                {
                    this.label_kkname.Visible = true;
                    Form_diyname form = new Form_diyname();
                    form.iskk = true;
                    form.diy_pass = this.label_kkname.Text;
                    form.Owner = this;
                    form.ShowDialog();
                    this.label_kkname.Text = form.diy_pass;
                    form.Dispose();
                }
                else
                {
                    this.label_kkname.Visible = false;
                }
            }
        }

        private void textBox_djuploadip_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_djuploadip.Tag = true;
            }
        }

        private void textBox_djuploadport_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_djuploadport.Tag = true;
            }
        }

        private void checkBox_DJFailReTry_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_DJFailReTry.Tag = true;
            }
        }

        private void comboBox_djnametype_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                comboBox_djnametype.Tag = true;

                if (comboBox_djnametype.Text == Enum_PicNameMode.自定义.ToString())
                {
                    this.label_djname.Visible = true;
                    Form_diyname form = new Form_diyname();
                    form.iskk = false;
                    form.diy_pass = this.label_djname.Text;
                    form.Owner = this;
                    form.ShowDialog();
                    this.label_djname.Text = form.diy_pass;
                    form.Dispose();
                }
                else
                {
                    this.label_djname.Visible = false;
                }
            }
        }

        private void textBox_compress_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_compress.Tag = true;
            }
        }

        private void param_Shown(object sender, EventArgs e)
        {
            start = true;
        }

        private void checkBox_DJPlateFilterEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_DJPlateFilterEnable.Tag = true;
            }
            checkBox_FiltNoPlate.Visible = checkBox_DJPlateFilterEnable.Checked;
            checkBox_FiltYellowPlate.Visible = checkBox_DJPlateFilterEnable.Checked;
            checkBox_FiltBluePlate.Visible = checkBox_DJPlateFilterEnable.Checked;
        }

        private void checkBox_FiltNoPlate_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_FiltNoPlate.Tag = true;
            }
        }

        private void checkBox_FiltYellowPlate_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_FiltNoPlate.Tag = true;
            }
        }

        private void checkBox_FiltBluePlate_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_FiltNoPlate.Tag = true;
            }
        }

        private void textBox_kksavedays_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_kksavedays.Tag = true;
            }
        }

        private void textBox_djsavedays_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_djsavedays.Tag = true;
            }
        }

        private void comboBox_SerialPort_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                comboBox_SerialPort.Tag = true;
            }
        }

        private void numericUpDown_ShutDownHour_ValueChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                numericUpDown_ShutDownHour.Tag = true;
            }
        }

        private void numericUpDown_ShutDownMinute_ValueChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                numericUpDown_ShutDownMinute.Tag = true;
            }
        }

        private void numericUpDown_ShutDownTimeSpan_ValueChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                numericUpDown_ShutDownTimeSpan.Tag = true;
            }
        }

        private void numericUpDown_RestartHour_ValueChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                numericUpDown_RestartHour.Tag = true;
            }
        }

        private void numericUpDown_RestartMinute_ValueChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                numericUpDown_RestartMinute.Tag = true;
            }
        }

        private void textBox_localIP_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_localIP.Tag = true;
            }
        }

        private void textBox_SynServerIP_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_SynServerIP.Tag = true;
            }
        }

        private void textBox_SynServerPort_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_SynServerPort.Tag = true;
            }
        }

        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                dataGridView1.Tag = true;
            }
        }

        private void dataGridView2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                dataGridView2.Tag = true;
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                if (lastnode != null) lastnode.BackColor = Color.White;
                e.Node.BackColor = Color.Gray;
                lastnode = e.Node;

                if (e.Action != TreeViewAction.ByMouse) return;

                if ((e.Node.Name.StartsWith("device_")) && (e.Node.Parent != null))
                {
                    string ip = e.Node.Tag.ToString();
                    treeView1.Tag = ip;
                    radioButton1.Checked = false;
                    radioButton2.Checked = false;
                    radioButton3.Checked = false;
                    radioButton4.Checked = false;
                    radioButton5.Checked = false;
                    radioButton6.Checked = false;
                }
                else
                {
                    treeView1.Tag = null;
                    pictureBox1.Image = null;
                }
            }
            catch { }
        }

        public void ShowPic(string ip)
        {
            try
            {
                if (G.Views != null)
                {
                    DeviceView view = (DeviceView)G.Views[ip];
                    string path = AppDomain.CurrentDomain.BaseDirectory + "\\focus\\" + ip + ".jpg";

                    if (File.Exists(path))
                    {
                        pictureBox1.LoadAsync(path);
                    }
                    else
                    {
                        if (pictureBox1.Image != null)
                        {
                            pictureBox1.Image.Dispose();
                            pictureBox1.Image = null;
                        }
                    }
                }
            }
            catch { }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (treeView1.Tag!=null)
                {
                    string ip = treeView1.Tag.ToString();
                    if (openFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        if (openFileDialog1.FileName != "")
                        {
                            pictureBox1.Load(openFileDialog1.FileName);
                            string path = AppDomain.CurrentDomain.BaseDirectory + "focus";
                            if (!Directory.Exists(path)) Directory.CreateDirectory(path);
                            File.Copy(openFileDialog1.FileName, path + "\\" + ip + ".jpg", true);
                        }
                    }
                }
            }
            catch { }
        }

        private void pictureBox1_LoadCompleted(object sender, AsyncCompletedEventArgs e)
        {
            try
            {
                if ((m_cd > 0) && (treeView1.Tag != null))
                {
                    if (G.Views != null)
                    {
                        string ip = treeView1.Tag.ToString();
                        DeviceView view = (DeviceView)G.Views[ip];
                        int left = 0;
                        int top = 0;
                        int right = 0;
                        int down = 0;
                        switch (m_cd)
                        {
                            case 1:
                                left = (int)(view.focusparam.left1 * pictureBox1.Width);
                                top = (int)(view.focusparam.top1 * pictureBox1.Height);
                                right = (int)(view.focusparam.right1 * pictureBox1.Width);
                                down = (int)(view.focusparam.down1 * pictureBox1.Height);
                                break;
                            case 2:
                                left = (int)(view.focusparam.left2 * pictureBox1.Width);
                                top = (int)(view.focusparam.top2 * pictureBox1.Height);
                                right = (int)(view.focusparam.right2 * pictureBox1.Width);
                                down = (int)(view.focusparam.down2 * pictureBox1.Height);
                                break;
                            case 3:
                                left = (int)(view.focusparam.left3 * pictureBox1.Width);
                                top = (int)(view.focusparam.top3 * pictureBox1.Height);
                                right = (int)(view.focusparam.right3 * pictureBox1.Width);
                                down = (int)(view.focusparam.down3 * pictureBox1.Height);
                                break;
                            case 4:
                                left = (int)(view.focusparam.left4 * pictureBox1.Width);
                                top = (int)(view.focusparam.top4 * pictureBox1.Height);
                                right = (int)(view.focusparam.right4 * pictureBox1.Width);
                                down = (int)(view.focusparam.down4 * pictureBox1.Height);
                                break;
                            case 5:
                                left = (int)(view.focusparam.left5 * pictureBox1.Width);
                                top = (int)(view.focusparam.top5 * pictureBox1.Height);
                                right = (int)(view.focusparam.right5 * pictureBox1.Width);
                                down = (int)(view.focusparam.down5 * pictureBox1.Height);
                                break;
                            case 6:
                                left = (int)(view.focusparam.left6 * pictureBox1.Width);
                                top = (int)(view.focusparam.top6 * pictureBox1.Height);
                                right = (int)(view.focusparam.right6 * pictureBox1.Width);
                                down = (int)(view.focusparam.down6 * pictureBox1.Height);
                                break;
                            default:
                                break;
                        }
                        if (g != null)
                        {
                            pictureBox1.Refresh();
                            g.DrawRectangle(pen, left, top, right - left, down - top);
                        }
                    }
                }
            }
            catch { }
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                if ((pictureBox1.Image != null) && (treeView1.Tag != null) && (m_cd > 0))
                {
                    startpoint.X = e.X;
                    startpoint.Y = e.Y;
                    endpoint.X = e.X;
                    endpoint.Y = e.Y;
                    blnDraw = true;
                }
            }
            catch { }
        }

        private void SetToolLabel(string txt)
        {
            try
            {
                this.toolStripStatusLabel1.Text = txt;
            }
            catch { }
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            try
            {
                if ((pictureBox1.Image != null) && (treeView1.Tag != null) && (m_cd > 0))
                {
                    string ip = treeView1.Tag.ToString();
                    double left = (double)startpoint.X / pictureBox1.Width;
                    double top = (double)startpoint.Y / pictureBox1.Height;
                    double right = (double)e.X / pictureBox1.Width;
                    double down = (double)e.Y / pictureBox1.Height;
                    if (g != null)
                    {
                        g.DrawRectangle(pen, startpoint.X, startpoint.Y, e.X - startpoint.X, e.Y - startpoint.Y);
                    }
                    if (G.Views != null)
                    {
                        DeviceView view = (DeviceView)G.Views[ip];
                        switch (m_cd)
                        {
                            case 1:
                                view.focusparam.left1 = left;
                                view.focusparam.top1 = top;
                                view.focusparam.right1 = right;
                                view.focusparam.down1 = down;
                                break;
                            case 2:
                                view.focusparam.left2 = left;
                                view.focusparam.top2 = top;
                                view.focusparam.right2 = right;
                                view.focusparam.down2 = down;
                                break;
                            case 3:
                                view.focusparam.left3 = left;
                                view.focusparam.top3 = top;
                                view.focusparam.right3 = right;
                                view.focusparam.down3 = down;
                                break;
                            case 4:
                                view.focusparam.left4 = left;
                                view.focusparam.top4 = top;
                                view.focusparam.right4 = right;
                                view.focusparam.down4 = down;
                                break;
                            case 5:
                                view.focusparam.left5 = left;
                                view.focusparam.top5 = top;
                                view.focusparam.right5 = right;
                                view.focusparam.down5 = down;
                                break;
                            case 6:
                                view.focusparam.left6 = left;
                                view.focusparam.top6 = top;
                                view.focusparam.right6 = right;
                                view.focusparam.down6 = down;
                                break;
                            default:
                                break;
                        }
                        bool flag = view.focusparam.Save();
                        if (flag == true)
                        {
                            G.Views[ip] = view;
                            MessageBox.Show("保存车道" + m_cd.ToString() + "特写区域成功:\r\nleft  =" + left.ToString() + "\r\ntop   =" + top.ToString() + "\r\nright =" + right.ToString() + "\r\ndown  =" + down.ToString());
                        }
                        else
                        {
                            MessageBox.Show("保存特写区域失败");
                        }
                    }
                    if (g != null)
                    {
                        pictureBox1.Refresh();
                        g.DrawRectangle(pen, startpoint.X, startpoint.Y, e.X - startpoint.X, e.Y - startpoint.Y);
                    }
                }    
                blnDraw = false;
            }
            catch { }
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            try
            {
                if (blnDraw)
                {

                    endpoint.X = e.X;
                    endpoint.Y = e.Y;

                    if (g != null)
                    {
                        pictureBox1.Invalidate();
                        g.DrawRectangle(pen, startpoint.X, startpoint.Y, endpoint.X - startpoint.X, endpoint.Y - startpoint.Y);
                    }
                }
            }
            catch { }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (treeView1.Tag != null)
                {
                    string ip = treeView1.Tag.ToString();
                    RadioButton box = sender as RadioButton;
                    if (box.Checked)
                    {
                        m_cd = 1;
                        ShowPic(ip);
                    }
                    else
                    {
                        m_cd = 0;
                    }
                }
            }
            catch { }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (treeView1.Tag != null)
                {
                    string ip = treeView1.Tag.ToString();
                    RadioButton box = sender as RadioButton;
                    if (box.Checked)
                    {
                        m_cd = 2;
                        ShowPic(ip);
                    }
                    else
                    {
                        m_cd = 0;
                    }
                }
            }
            catch { }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (treeView1.Tag != null)
                {
                    string ip = treeView1.Tag.ToString();
                    RadioButton box = sender as RadioButton;
                    if (box.Checked)
                    {
                        m_cd = 3;
                        ShowPic(ip);
                    }
                    else
                    {
                        m_cd = 0;
                    }
                }
            }
            catch { }
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (treeView1.Tag != null)
                {
                    string ip = treeView1.Tag.ToString();
                    RadioButton box = sender as RadioButton;
                    if (box.Checked)
                    {
                        m_cd = 4;
                        ShowPic(ip);
                    }
                    else
                    {
                        m_cd = 0;
                    }
                }
            }
            catch { }
        }

        private void radioButton5_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (treeView1.Tag != null)
                {
                    string ip = treeView1.Tag.ToString();
                    RadioButton box = sender as RadioButton;
                    if (box.Checked)
                    {
                        m_cd = 5;
                        ShowPic(ip);
                    }
                    else
                    {
                        m_cd = 0;
                    }
                }
            }
            catch { }
        }

        private void radioButton6_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (treeView1.Tag != null)
                {
                    string ip = treeView1.Tag.ToString();
                    RadioButton box = sender as RadioButton;
                    if (box.Checked)
                    {
                        m_cd = 6;
                        ShowPic(ip);
                    }
                    else
                    {
                        m_cd = 0;
                    }
                }
            }
            catch { }
        }

        private bool Savecd(string roadid, string direactionid, string cdid, double left, double top, double right, double down)
        {
            bool ans = false;
            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(AppDomain.CurrentDomain.BaseDirectory + "Param.xml");
                string xpath = string.Format("param/road[@id='{0}']/direction[@id='{1}']/cd[@id='{2}']", roadid, direactionid, cdid);
                XmlNode node = doc.SelectSingleNode(xpath);
                if (node != null)
                {
                    node.Attributes["left"].Value = left.ToString();
                    node.Attributes["top"].Value = top.ToString();
                    node.Attributes["right"].Value = right.ToString();
                    node.Attributes["down"].Value = down.ToString();
                    doc.Save(AppDomain.CurrentDomain.BaseDirectory + "Param.xml");
                    ans = true;
                }
            }
            catch { ans = false; }
            return ans;
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            try
            {
                if (g != null)
                {
                    g.Dispose();
                }
            }
            catch { }
        }

        private void radioButton_A2_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_A2.Checked == true)
                {
                    radioButton_No2.Tag = Enum_PicJoinMode.A2;
                }
            }
        }

        private void radioButton_B2_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_B2.Checked == true)
                {
                    radioButton_No2.Tag = Enum_PicJoinMode.B2;
                }
            }
        }

        private void radioButton_A3_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_A3.Checked == true)
                {
                    radioButton_No3.Tag = Enum_PicJoinMode.A3;
                }
            }
        }

        private void radioButton_B3_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_B3.Checked == true)
                {
                    radioButton_No3.Tag = Enum_PicJoinMode.B3;
                }
            }
        }

        private void radioButton_A4_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_A4.Checked == true)
                {
                    radioButton_No4.Tag = Enum_PicJoinMode.A4;
                }
            }
        }

        private void radioButton_B4_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_B4.Checked == true)
                {
                    radioButton_No4.Tag = Enum_PicJoinMode.B4;
                }
            }
        }

        private void radioButton_No2_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_No2.Checked == true)
                {
                    radioButton_No2.Tag = Enum_PicJoinMode.No;
                }
            }
        }

        private void radioButton_No3_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_No3.Checked == true)
                {
                    radioButton_No3.Tag = Enum_PicJoinMode.No;
                }
            }
        }

        private void radioButton_No4_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_No4.Checked == true)
                {
                    radioButton_No4.Tag = Enum_PicJoinMode.No;
                }
            }
        }

        private void checkBox_kktailEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_kktailEnable.Tag = true;
            }
        }

        private void checkBox_djtailEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_djtailEnable.Tag = true;
            }
        }
        //
        private void checkBox_printEnable_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_printEnable.Tag = true;
            }
        }

        private void checkBox_printtime_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_printtime.Tag = true;
            }
        }

        private void checkBox_printroad_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_printroad.Tag = true;
            }
        }

        private void checkBox_printdirection_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_printdirection.Tag = true;
            }
        }

        private void checkBox_printcd_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_printcd.Tag = true;
            }
        }

        private void checkBox_printcapturesystem_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_printcapturesystem.Tag = true;
            }
        }

        private void checkBox_printplatecolor_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_printplatecolor.Tag = true;
            }
        }

        private void checkBox_printhphm_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_printhphm.Tag = true;
            }
        }

        private void checkBox_printsbbh_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_printsbbh.Tag = true;
            }
        }

        private void checkBox_printfwm_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_printfwm.Tag = true;
            }
        }

        private void radioButton_printtop_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_printtop.Checked == true)
                {
                    radioButton_printtop.Tag = Enum_PrintPosition.Top;
                }
            }
        }

        private void radioButton_printdown_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_printdown.Checked == true)
                {
                    radioButton_printtop.Tag = Enum_PrintPosition.Down;
                }
            }
        }

        private void comboBox_kksubfolder_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                comboBox_kksubfolder.Tag = true;

                if (comboBox_kksubfolder.Text == Enum_SubFolderMode.自定义.ToString())
                {
                    this.label_kkdiy.Visible = true;
                    Form_diyfolder form = new Form_diyfolder();
                    form.diy = this.label_kkdiy.Text;
                    form.Owner = this;
                    form.ShowDialog();
                    this.label_kkdiy.Text = form.diy;
                    form.Dispose();
                }
                else
                {
                    this.label_kkdiy.Visible = false;
                }
            }
        }

        private void comboBox_djsubfolder_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                comboBox_djsubfolder.Tag = true;

                if (comboBox_djsubfolder.Text == Enum_SubFolderMode.自定义.ToString())
                {
                    this.label_djdiy.Visible = true;
                    Form_diyfolder form = new Form_diyfolder();
                    form.diy = this.label_djdiy.Text;
                    form.Owner = this;
                    form.ShowDialog();
                    this.label_djdiy.Text = form.diy;
                    form.Dispose();
                }
                else 
                {
                    this.label_djdiy.Visible = false;
                }
            }
        }

        private void checkBox_kkplateenable_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                
                    checkBox_kkplateenable.Tag = true;
                
            }
        }

        private void checkBox_djplateenable_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                
                    checkBox_djplateenable.Tag = true;
                
            }
        }

        private void cboPicCheck_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                cboPicCheck.Tag = true;
            }
        }

        private int GetKKFailCount()
        {
            int ans = 0;
            try
            {
                DataTable dt = db.DBHelper.GetInstance().Select("FailRecord_t", "P5", "P5='0'");
                if ((dt != null) && (dt.Rows != null) && (dt.Rows.Count > 0))
                {
                    ans = dt.Rows.Count;
                }
            }
            catch { }
            return ans;
        }
        private int GetKKPushCount()
        {
            int ans = 0;
            try
            {
                DataTable dt = db.DBHelper.GetInstance().Select("PushRecord_t", "P5", "P5='0'");
                if ((dt != null) && (dt.Rows != null) && (dt.Rows.Count > 0))
                {
                    ans = dt.Rows.Count;
                }
            }
            catch { }
            return ans;
        }
        private void button_clearKK_Click(object sender, EventArgs e)
        {
            try
            {
                if (kkcount>0)
                {
                    bool del = db.DBHelper.GetInstance().Delete("FailRecord_t", "P5='0'");
                    if (del == true)
                    {
                        kkcount = 0;
                        this.label_kkcount.Text = "0条";
                    }
                    MessageBox.Show(del ? "清空卡口重传历史记录成功" : "清空卡口重传历史记录失败");
                }
                else
                {
                    MessageBox.Show("卡口记录为空");
                }
                
            }
            catch { }
        }

        private int GetDJFailCount()
        {
            int ans = 0;
            try
            {
                DataTable dt = db.DBHelper.GetInstance().Select("FailRecord_t", "P5", "P5<>'0'");
                if ((dt != null) && (dt.Rows != null) && (dt.Rows.Count > 0))
                {
                    ans = dt.Rows.Count;
                }
            }
            catch { }
            return ans;
        }
        private int GetDJPushCount()
        {
            int ans = 0;
            try
            {
                DataTable dt = db.DBHelper.GetInstance().Select("PushRecord_t", "P5", "P5<>'0'");
                if ((dt != null) && (dt.Rows != null) && (dt.Rows.Count > 0))
                {
                    ans = dt.Rows.Count;
                }
            }
            catch { }
            return ans;
        }
        private void button_clearDJ_Click(object sender, EventArgs e)
        {
            try
            {
                
                if (djcount>0)
                {
                    bool del = db.DBHelper.GetInstance().Delete("FailRecord_t", "P5<>'0'");
                    if (del == true)
                    {
                        djcount = 0;
                        this.label_djcount.Text = "0条";
                    }
                    MessageBox.Show(del ? "清空电警重传历史记录成功" : "清空电警重传历史记录失败");
                }
                else
                {
                    MessageBox.Show("电警记录为空");
                }
            }
            catch { }
        }

        private void radioButton_http_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_http.Checked == true)
                {
                    radioButton_http.Tag = Enum_WebPathType.HTTP;
                }
            }
        }

        private void radioButton_ftp_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_ftp.Checked == true)
                {
                    radioButton_http.Tag = Enum_WebPathType.FTP;
                }
            }
        }

        private void textBox_mquri_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_mquri.Tag = true;
            }
        }

        private void textBox_mqtopic_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_mqtopic.Tag = true;
            }
        }

        private void textBox_pushport_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_pushport.Tag = true;
            }
        }

        private void checkBox_kkpushenable_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_kkpushenable.Tag = true;
            }
        }

        private void checkBox_kkrepushenable_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_kkrepushenable.Tag = true;
            }
        }

        private void checkBox_djpushenable_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_djpushenable.Tag = true;
            }
        }

        private void checkBox_djrepushenable_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                checkBox_djrepushenable.Tag = true;
            }
        }

        private void radioButton_Send_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_Send.Checked == true)
                {
                    radioButton_Send.Tag = JRCore.enums.Enum_TcpWorkMode.Send;
                }
            }
        }

        private void radioButton_SendRead_CheckedChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                if (radioButton_SendRead.Checked == true)
                {
                    radioButton_Send.Tag = JRCore.enums.Enum_TcpWorkMode.SendRead;
                }
            }
        }

        private void textBox_pushtimeout_TextChanged(object sender, EventArgs e)
        {
            if (start == true)
            {
                button_ok.Enabled = true;
                textBox_pushtimeout.Tag = true;
            }
        }

        private void button_kkclearpush_Click(object sender, EventArgs e)
        {
            try
            {
                if (kkpushcount > 0)
                {
                    bool del = db.DBHelper.GetInstance().Delete("PushRecord_t", "P5='0'");
                    if (del == true)
                    {
                        kkpushcount = 0;
                        this.label_kkpushcount.Text = "0条";
                    }
                    MessageBox.Show(del ? "清空卡口推送历史记录成功" : "清空卡口推送历史记录失败");
                }
                else
                {
                    MessageBox.Show("卡口记录为空");
                }

            }
            catch { }
        }

        private void button_djclearpush_Click(object sender, EventArgs e)
        {
            try
            {

                if (djpushcount > 0)
                {
                    bool del = db.DBHelper.GetInstance().Delete("PushRecord_t", "P5<>'0'");
                    if (del == true)
                    {
                        djpushcount = 0;
                        this.label_djpushcount.Text = "0条";
                    }
                    MessageBox.Show(del ? "清空电警推送历史记录成功" : "清空电警推送历史记录失败");
                }
                else
                {
                    MessageBox.Show("电警记录为空");
                }
            }
            catch { }
        }
    }
}
